home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / STDR / RapidEquilibriumPReactor.rd < prev    next >
Text File  |  2000-03-03  |  5KB  |  189 lines

  1. @CLASSNAME: RapidEquilibriumPReactor
  2.  
  3. @BASECLASS: Reactor
  4. @AUTHOR: Kenta Hashimoto
  5. @EMAIL: kem@sfc.keio.ac.jp
  6. @DATE: 2000 2/2
  7.  
  8. #%VERSION: E-CELL, Reactor 
  9. %VERSION: ecs-1.0, 0.1
  10.  
  11. @BRIEF_DESCRIPTION: Binding reaction which rapidly reaches equilibrium
  12.  
  13. @DESCRIPTION: A reactor class for binding reactions which rapidly (within
  14. a step) reaches a state of equilibrium.
  15.  
  16. This reactor calculates velocity according to the equilibrium constant
  17. inputted by the user. In case where two substrates are already at a
  18. state of equilibrium, velocity is set to zero.
  19.  
  20. @EQUATION:$$k_{eq} \prod ([S_{k}] - v) =  \prod ([P_{k}] + v)$$
  21.  
  22. ####%SUBSTANCE: max, min
  23.  
  24. %SUBSTANCE:Substrate, inf, 1
  25. %SUBSTANCE:Product, inf, 1
  26.  
  27. ####%PARAMETER?: NAME,TYPE,DESCRIPTION
  28.  
  29. %PARAMETER: Keq, Float, $M^{(N_{P}) - (N_{S})}$, Equilibrium constant
  30. @NOTES: ''v'' is velocity. \\ $N_{P}$ is number of Products, $N_{S}$ is number of Substrates. 
  31.  
  32. #######  for .h file ##########
  33.  
  34. %INCLUDE_FILE_H: StandardHeaders.h
  35.  
  36. @PRIVATE:
  37. @PROTECTED:
  38. @PUBLIC:
  39.  
  40. #######  for .C file ##########
  41.  
  42. #%INCLUDE_FILE_C: RootSystem.C
  43.  
  44. @INITIALIZE_FUNC:
  45.   int d_Keq = 0;
  46.  // Keq_qua = Keq * N_A^(sum_numPro - sum_numSub) * V^(sum_numPro - sum_numSub)
  47.   for(int i=0; i<numSubstrate(); i++)
  48.     d_Keq -= substrate(i)->coefficient();
  49.   for(int i=0; i<numProduct(); i++)
  50.     d_Keq += product(i)->coefficient();
  51.   Keq *= pow(N_A, d_Keq);
  52. @REACT_FUNC:
  53. {
  54.   Float d = 0;
  55.   int figure = 0;
  56.   Float velocity = 0;
  57.   Float velocity_posi = 1;
  58.   Float velocity_nega = 1;
  59.   int least = 0;
  60.   Float Keq_qua = 1;
  61.  
  62.   ////
  63.   for(int i=0; i<numSubstrate(); i++)
  64.     for(int j=0; j<substrate(i)->coefficient(); j++)
  65.       Keq_qua *= substrate(i)->substance().supersystem()->volume();
  66.   Keq_qua = Keq / Keq_qua;
  67.   for(int i=0; i<numProduct(); i++)
  68.     for(int j=0; j<product(i)->coefficient(); j++)
  69.       Keq_qua *= product(i)->substance().supersystem()->volume();
  70.  
  71.   ////
  72.   for(int i=0; i<numSubstrate(); i++)
  73.     for(int j=0 ; j<substrate(i)->coefficient(); j++)
  74.       velocity_posi *= substrate(i)->quantity();
  75.   velocity_posi *= Keq_qua;
  76.  
  77.   for(int i=0; i<numProduct(); i++)
  78.     for(int j=0; j<product(i)->coefficient(); j++)
  79.       velocity_nega *= product(i)->quantity();
  80.  
  81.   ////
  82.   if(velocity_posi > velocity_nega){
  83.  
  84.     for(int i=0; i<numSubstrate(); i++)
  85.       if(substrate(i)->quantity() / substrate(i)->coefficient() 
  86.          < substrate(least)->quantity() / substrate(least)->coefficient())
  87.         least = i;
  88.     
  89.     figure = (int)log10(substrate(least)->quantity()
  90.             / substrate(least)->coefficient());
  91.       
  92.     d = pow(10L,figure);
  93.     while(figure >= 0){
  94.       velocity += d;
  95.       
  96.       if(substrate(least)->quantity() 
  97.          < velocity * substrate(least)->coefficient()){
  98.         velocity -= d;
  99.         figure--;
  100.     d /= 10;
  101.         continue;
  102.       }
  103.  
  104.       velocity_posi = 1; velocity_nega = 1;
  105.       for(int i=0; i<numSubstrate(); i++)
  106.     for(int j=0; j<substrate(i)->coefficient(); j++)
  107.       velocity_posi *= substrate(i)->quantity() - 
  108.           (velocity * substrate(i)->coefficient());
  109.       velocity_posi *= Keq_qua;
  110.       for(int i=0; i<numProduct(); i++)
  111.     for(int j=0; j<product(i)->coefficient(); j++)
  112.       velocity_nega *= product(i)->quantity() + 
  113.         (velocity * product(i)->coefficient());
  114.  
  115.       if(velocity_posi == velocity_nega)
  116.         break;
  117.       else if(velocity_posi < velocity_nega){
  118.         velocity -= d;
  119.         figure--;
  120.     d /= 10;
  121.       }
  122.       else
  123.         continue;
  124.     }
  125.   }
  126.  
  127.   else if(velocity_posi < velocity_nega ){
  128.  
  129.     for(int i=0; i<numProduct(); i++)
  130.       if(product(i)->quantity() / product(i)->coefficient() 
  131.          < product(least)->quantity() / product(least)->coefficient())
  132.         least = i;
  133.  
  134.     figure = (int)log10((double)product(least)->quantity()
  135.                         / product(least)->coefficient());
  136.  
  137.     d = pow(10L,figure);
  138.  
  139.     while(figure >= 0){
  140.       velocity -= d;
  141.       
  142.       if(product(least)->quantity() + (velocity * product(least)->coefficient()) < 0){
  143.         velocity += d;
  144.         figure--;
  145.     d *= 10;
  146.         continue;
  147.       }
  148.  
  149.       velocity_posi =1; velocity_nega =1;
  150.       for(int i=0; i<numSubstrate(); i++)
  151.     for(int j=0 ; j<substrate(i)->coefficient() ; j++)
  152.       velocity_posi *= 
  153.         substrate(i)->quantity() - (velocity * substrate(i)->coefficient());
  154.       velocity_posi *= Keq_qua;
  155.       for(int i=0; i<numProduct(); i++)
  156.     for(int j=0; j<product(i)->coefficient(); j++)
  157.       velocity_nega *=
  158.         product(i)->quantity() + (velocity * product(i)->coefficient());
  159.  
  160.       if(velocity_posi < velocity_nega){
  161.         continue;
  162.       }
  163.       else if(velocity_posi > velocity_nega){
  164.         velocity += d;
  165.         figure--;
  166.     d /= 10;
  167.       }
  168.       else
  169.         break;
  170.     }
  171.   }  
  172.   else
  173.     velocity = 0;
  174.  
  175.   setActivity(velocity);
  176.  
  177.   int i = numSubstrate();    
  178.   do{
  179.     i--;
  180.     substrate(i)->setQuantity(substrate(i)->quantity() - velocity * substrate(i)->coefficient());
  181.   }while(i!=0);
  182.   i = numProduct();
  183.   do{
  184.     i--;
  185.     product(i)->setQuantity(product(i)->quantity() + velocity * product(i)->coefficient());
  186.   }while(i!=0);
  187. }
  188. @OPTION_C:
  189.